package com.example.demo.controller;

import com.example.demo.admin.dto.SearchDto;
import com.example.demo.admin.pojo.PageResult;
import com.example.demo.admin.pojo.Result;
import com.example.demo.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;
    //获取全部部门信息
    @GetMapping()
    public Result<PageResult> getAllDept(SearchDto searchDto){
        log.info("获取部门全部信息{}",searchDto);
        PageResult pageResult = deptService.getAllDept(searchDto);
        return Result.success(pageResult);
    }

    //删除部门信息
    @DeleteMapping()
    public Result deleteDept(Long id){
        log.info("删除部门{}",id);
        deptService.deleteDeptById(id);
        return Result.success();
    }

    //添加部门
    @PostMapping("/{deptName}")
    public Result addDept(@PathVariable String deptName){
        log.info("添加参数{}",deptName);
        deptService.addDept(deptName);
        return Result.success();
    }

    //编辑部门
    @PutMapping("/{id}/{deptName}")
    public Result editDept(@PathVariable String deptName,@PathVariable Long id){
        log.info("编辑参数{}{}",deptName,id);
        deptService.editDept(deptName,id);
        return Result.success();
    }

}
